{{template "head.tpl" .}}
{{template "topnav.tpl" .}}

<!--  页面，预留15px的空间。 -->
<div style="padding: 100px;">
    <!--  采用 layui-row 来定义行 -->
    <div class="layui-row layui-col-space15">
        <!--
            定义列宽
            列可以同时出现最多四种不同的组合，
            分别是：xs（超小屏幕，如手机）、sm（小屏幕，如平板）、md（桌面中等屏幕）、lg（桌面大型屏幕），
            以呈现更加动态灵活的布局。
        -->
        <div class="layui-col-md6 layui-col-sm6 layui-col-lg6 layui-col-md-offset3">

            <!--  定义一个面板 -->
            <div class="layui-card">
                <!--  面板标题 -->
                <div class="layui-card-header">用户登录</div>
                <!--  面板内容主体 -->
                <div class="layui-card-body">





<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
          <input type="text" name="username" required  lay-verify="required|userlenth" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">输入密码</label>
        <div class="layui-input-block">
          <input type="password" name="password" id="id_password" required lay-verify="required|pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="LoginSubmit">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
</form>
 
                </div>
            </div>
            <!--  定义一个面板 -->

        </div>
        <!--  一列 -->
    </div>
    <!--  采用 layui-row 来定义行 -->

<script>
//JavaScript代码区域
layui.use(['form','jquery', 'layedit', 'element'], function() {
  var element = layui.element;
  var $ = layui.jquery;
  var layedit = layui.layedit;
  var form = layui.form;
  var index = parent.layer.getFrameIndex(window.name);
  element.render();
  form.render();
  function sleep (time) {
  return new Promise((resolve) => setTimeout(resolve, time));
}
  form.verify({
    userlenth: function(value){
      if(value.length < 5){
        return '用户名至少得6个字符，且不能出现空格';
      }
    },
    pass: [
      /^[\S]{8,24}$/,
      '密码必须8到24位，且不能出现空格'
    ],
    issame: function(value){
      passwd = layui.jquery("#id_password").val();
      if (passwd != value) {
        return '两次输入的密码不一致'
      }
    },
    content: function(value){
      layedit.sync(editIndex);
    }
  });
  form.on('submit(LoginSubmit)', function(data){
    //layer.msg(JSON.stringify(data.field));
    var posturl = window.location.pathname;
    //console.log(posturl)
    var username = data.field.username;
    var password = data.field.password;
    //var repassword = data.field.repassword;
    //console.log(lastname);
    //return false;
    
    $.post(posturl, {
      "username": username,
      "password": password,
      //"repassword": repassword,
    }, function (result,status) {
      var msg = result.msg;
        layer.msg(msg);
        if (result.code == 0) {
          //sleep(2000);
          sleep(1000).then(() => {
             //self.location.href="/"
             console.log("success");
             window.history.back(-1);
})
         
        }
    });
    return false;
  });
})
</script>
</body>
</html>